module Tipos

where

type Usuario = Int
type Keyword = String
type Puntaje = Int
type Numero = Int
type Texto = String

-- Palabras --
 
palabras :: String -> [String]
palabras string =
        palabrasAux (separarCaracteres (normalizarEspacios (limpiarCaracteres string)))

palabrasAux :: [String] -> [String]
palabrasAux [] = []
palabrasAux [x] = [x]
palabrasAux (x:(y:(xs))) | y == " " = [x] ++ (palabrasAux xs)
                         | otherwise = palabrasAux ([(x ++ y)] ++ xs)
                            
separarCaracteres :: String -> [String]
separarCaracteres [] = []
separarCaracteres (x:xs) = [[x]] ++ (separarCaracteres xs)

caracteresNoValidos = ['\191','?','\161','!','.',',',';']
limpiarCaracteres :: String -> String
limpiarCaracteres [] = []
limpiarCaracteres (x:xs) | x `elem` caracteresNoValidos = limpiarCaracteres xs
                         | otherwise = x : limpiarCaracteres xs
                     
normalizarEspacios :: String -> String
normalizarEspacios x = sacarPrimerEspacio (normalizarEspaciosAux x)
                      
normalizarEspaciosAux :: String -> String 
normalizarEspaciosAux [] = ""
normalizarEspaciosAux " " = "" {-Saco el ultimo espacio-}
normalizarEspaciosAux [x] = [x]
normalizarEspaciosAux (x:(y:(xs))) | x == ' ' && y == ' '  = normalizarEspaciosAux (x:xs)
                                     | otherwise = x : normalizarEspaciosAux (y:xs)

sacarPrimerEspacio :: String -> String
sacarPrimerEspacio [] = ""
sacarPrimerEspacio (' ':xs) = xs
sacarPrimerEspacio xs = xs

-- Fin palabras -- 




-- Funciones para strings --

damePalabra :: String -> String
damePalabra [] = []
damePalabra string = palabras (string) !! 0
                   
sacarPalabra :: String -> String
sacarPalabra [] =  []
sacarPalabra string = sacarPalabraAux (palabras string)

sacarPalabraAux :: [String] -> String
sacarPalabraAux [x] = []
sacarPalabraAux (x:xs) = xs `unirCon` ' '

unirCon :: [String] -> Char -> String
unirCon [] _ = []
unirCon [x] _ = x
unirCon (x:xs) plasticola = x ++ [plasticola] ++ (unirCon xs plasticola) 

segundaPalabra :: String -> String
segundaPalabra string = damePalabra (sacarPalabra string)

intToString:: Int -> String
intToString a = show a

-- Fin funciones para strings --

sacarRepetidos :: Eq lista => [lista] -> [lista]
sacarRepetidos [] = []
sacarRepetidos (x:xs) | x `elem` xs = sacarRepetidos xs
                      | otherwise = x : sacarRepetidos xs 
                      
